import bcrypt


def password_hash(password: str) -> str:
    """
    对密码进行哈希加密
    :param password: 需要加密的明文密码
    :return: 
    """
    hashed_bytes = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
    return hashed_bytes.decode('utf-8')


def verify_password(password: str, hashed: str) -> bool:
    """
    校验明文密码与哈希是否一致
    :param password: 明文密码
    :param hashed: 加密后的哈希值
    :return:
    """
    return bcrypt.checkpw(
        password.encode('utf-8'),
        hashed.encode('utf-8')
    )


if __name__ == '__main__':
    print(password_hash('123456'))
